using System;
using System.Collections;
using System.Text;
using System.IO;
using System.Collections.Generic;

namespace TheLogWatcher
{
    public class AccessReaderHandler
    {
        public AccessReaderHandler(Dictionary<MessageTypes, List<LogEntry>> data, DataAccess dataAccess)
        {
            this.data = data;
            this.dataAccess = dataAccess;
        }

        private DataAccess dataAccess;

        private Dictionary<MessageTypes, List<LogEntry>> data;

        /// <summary>
        ///     Reads a single entry at the given position from a
        ///     log file that contains the specified message type.
        /// </summary>
        /// <param name="type"></param>
        /// <param name="lineIndex"></param>
        /// <returns>LogEntry</returns>
        public LogEntry readEntry(MessageTypes type, long fileStreamStartPos, long fileStreamEndPos)
        {
            LogFile logfile = this.dataAccess.FnProvider.GetLogFile(type);
            if (logfile != null)
            {
                LogfileReader reader = new LogfileReader(this.data, logfile.Filename);
                LogEntry entry = reader.readSingleEntry(logfile.Logformat, fileStreamStartPos, fileStreamEndPos);

                return entry;
            }
            return null;
        }
    }
}
